Skip to content

docs: point to native readonly and keep the library as a z-engine showcase - #18

Merged
lisachenko merged 1 commit into
masterfrom
feature/wonderful-johnson-03ot8f
Nov 21, 2026
Merged

lisachenko merged 1 commit into
masterfrom
feature/wonderful-johnson-03ot8f

Conversation

@lisachenko

Copy link
Copy Markdown
Owner

Why

This library was written when PHP had no way to stop a property from changing after construction, and the Immutability RFC had stalled. The language has caught up since, so for new code the honest advice is "use readonly". This PR says that up front, and explains why the repository is still worth keeping.

What changes

  • New "Status: PHP has this built in now" section at the top of the README, with a showcase status badge.
    • A table of the native features that replace the library: readonly properties (8.1), readonly classes (8.2), readonly re-initialization in __clone() (8.3), asymmetric visibility public private(set) (8.4), and clone($obj, [...]) (8.5).
    • A plain-PHP final readonly class Money example, with a wither built on clone with.
  • "So why keep this repository?" frames it as a compact, tested example of rewriting the engine from PHP: hooking interface_gets_implemented, replacing create_object to give each instance its own handler table, overriding write_property / unset_property / get_property_ptr_ptr, and checking at start-up that the interception really works under OPcache (z-engine#238). It points readers to the existing "Low-level details (for geeks)" section.
  • "Rationale" becomes "Rationale (historical)", reworded in the past tense so it no longer says PHP lacks immutability.
  • The tagline and the composer.json description describe the library as handler-rewriting via z-engine and a showcase, instead of "native immutable objects".

No code or CI changes. The library keeps running on PHP 8.4, 8.5 and 8.6.

Checked

  • The README's native example behaves as documented on PHP 8.5.13 and 8.6.0:
    • the write throws Error: Cannot modify readonly property Money::$amount;
    • withAmount(80) returns a new object and leaves the original untouched.
  • clone with only works inside the class (a wither): from global scope it fails with "Cannot modify protected(set) readonly property", so the example uses a method.
  • composer validate --strict passes.

Generated by Claude Code

…wcase

PHP gained readonly properties (8.1), readonly classes (8.2), readonly
re-initialization in __clone (8.3), asymmetric visibility (8.4) and clone
with (8.5), so new code needs neither FFI nor this library to get immutable
objects. The README now says so up front, with a native example, and
explains why the repository stays: a compact, tested example of rewriting
engine object handlers from PHP. The old rationale is kept, marked
historical, and the composer description follows.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FxhC1D34vSRsQVcgd3HwS6
@lisachenko
lisachenko marked this pull request as ready for review November 21, 2026 14:52
@lisachenko
lisachenko merged commit fe5918e into master Nov 21, 2026
7 checks passed
@lisachenko
lisachenko deleted the feature/wonderful-johnson-03ot8f branch November 21, 2026 14:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants